package org.apache.cayenne.extentions.modeler;

import java.io.File;

import javax.swing.WindowConstants;

import org.apache.cayenne.Activator;
import org.apache.cayenne.modeler.Application;
import org.apache.cayenne.modeler.CayenneModelerController;
import org.apache.cayenne.modeler.CayenneModelerFrame;
import org.apache.cayenne.modeler.action.GenerateCodeAction;
import org.apache.cayenne.modeler.dialog.codegen.CodeGeneratorController;
import org.apache.cayenne.modeler.init.platform.PlatformInitializer;
import org.apache.cayenne.map.DataMap;
import org.eclipse.core.runtime.Path;

public class PluginModelerController extends CayenneModelerController {

	public PluginModelerController(Application application) {
		super(application);
		this.frame = new PluginModelerFrame(application.getActionManager());

        application
                .getInjector()
                .getInstance(PlatformInitializer.class)
                .setupMenus(frame);

	}
	

	@Override
	public void projectSavedAction() {
//		((GenerateCodeAction) Application.getInstance().getAction(
//				GenerateCodeAction.getActionName()))
//				.performGenerationOnAllDataMaps();
		
		 DataMap dataMap = application.getFrameController().getProjectController().getCurrentDataMap();
		 if (dataMap != null) {
	            new CodeGeneratorController(getApplication().getFrameController(), dataMap)
	                    .startup();
	        }
		
		Activator.getDefault().updateWorkspace(
				new Path(projectController.getProject()
						.getConfigurationResource().getURL().getPath()));
		System.out.println("################################# saved action");
		super.projectSavedAction();

	}
//
	@Override
	protected void initBindings() {
		super.initBindings();
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

	}
//
////	@Override
////	protected CayenneModelerFrame initModelerFrame(Application application) {
////		return new PluginModelerFrame(application.getActionManager());
////	}

}